package com.ruoyi.web.controller.asset;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.MaintenancePlan;
import com.ruoyi.asset.service.IMaintenancePlanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修保养计划Controller
 * 
 * @author ruoyi
 * @date 2023-04-06
 */
@Controller
@RequestMapping("/asset/plan")
public class MaintenancePlanController extends BaseController
{
    private String prefix = "asset/plan";

    @Autowired
    private IMaintenancePlanService maintenancePlanService;

    @RequiresPermissions("asset:plan:view")
    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询维修保养计划列表
     */
    @RequiresPermissions("asset:plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaintenancePlan maintenancePlan)
    {
        startPage();
        List<MaintenancePlan> list = maintenancePlanService.selectMaintenancePlanList(maintenancePlan);
        return getDataTable(list);
    }

    /**
     * 导出维修保养计划列表
     */
    @RequiresPermissions("asset:plan:export")
    @Log(title = "维修保养计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaintenancePlan maintenancePlan)
    {
        List<MaintenancePlan> list = maintenancePlanService.selectMaintenancePlanList(maintenancePlan);
        ExcelUtil<MaintenancePlan> util = new ExcelUtil<MaintenancePlan>(MaintenancePlan.class);
        return util.exportExcel(list, "维修保养计划数据");
    }

    /**
     * 新增维修保养计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存维修保养计划
     */
    @RequiresPermissions("asset:plan:add")
    @Log(title = "维修保养计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaintenancePlan maintenancePlan)
    {
        return toAjax(maintenancePlanService.insertMaintenancePlan(maintenancePlan));
    }

    /**
     * 修改维修保养计划
     */
    @RequiresPermissions("asset:plan:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MaintenancePlan maintenancePlan = maintenancePlanService.selectMaintenancePlanById(id);
        mmap.put("maintenancePlan", maintenancePlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存维修保养计划
     */
    @RequiresPermissions("asset:plan:edit")
    @Log(title = "维修保养计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaintenancePlan maintenancePlan)
    {
        return toAjax(maintenancePlanService.updateMaintenancePlan(maintenancePlan));
    }

    /**
     * 删除维修保养计划
     */
    @RequiresPermissions("asset:plan:remove")
    @Log(title = "维修保养计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(maintenancePlanService.deleteMaintenancePlanByIds(ids));
    }
}
